/*
 * @Author: czy
 * @Date: 2021-07-13 00:06:32
 * @LastEditTime: 2021-07-15 19:24:10
 */
#include "sys/type.h"
#include "sys/const.h"
#include "sys/system.h"

#include "../lib/state.h"

extern PCB *current_process;

void init_task(int (*tskBody)(void))
{
    PCB task;
    task.pid = 0;
    task.state = RUNNING;
    task.priority = 0;
    task.total_run_time = -1;
    task.last_run_time = -1;
    task.running_times = -1;
    task.PC = (unsigned int)tskBody;
    allocblock(&(task.heap), &(task.stack));
    unsigned int address = (unsigned int)processEnd;
    memcpy((void *)(task.stack), &address, 4);
    task.stack -= 4;
    context_switch(current_process, &task);
}